﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Com.Charence.PassManager.Common.Messages
{
    public class MessageManager
    {
        private static MessageManager _current;
        public static MessageManager Current
        {
            get
            {
                if (_current == null)
                    _current = new MessageManager();
                return _current;
            }
        }

        public string this[string key]
        {
            get
            {
                XElement xml = XElement.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\Messages\Messages.xml"));
                var messageNode = xml.Elements("messages").Elements("message").FirstOrDefault(p => p.Attribute("key").Value == key);
                
                if (messageNode == null) return null;

                return messageNode.Attribute("value").Value;
            }
        }
    }
}
